package com.cat.utils;

import java.io.Serializable;

/**
 * 用于页面返回结果.
 * <ul>
 * <li>正确的结果放入result则success为true,表示成功得到结果集</li>
 * <li>错误的信息放入error则success为false,表示有错误信息</li>
 * </ul>
 *
 * @Author Will Tong
 */
public class Response<T> implements Serializable {

    private static final int DEFAULT_SUCCESS_CODE = 200;
    private static final int DEFAULT_ERROR_CODE = 400;
    private T data;
    private String msg;
    private int code;

    public void setSuccess() {
        this.code = DEFAULT_SUCCESS_CODE;
        this.msg = "操作成功";
    }

    public void setSuccess(T datas) {
        this.code = DEFAULT_SUCCESS_CODE;
        this.msg = "操作成功";
        this.data = datas;
    }

    public void setSuccess(int code ,T datas) {
        this.code = code;
        this.data = datas;
    }

    public void setError() {
        this.code = DEFAULT_ERROR_CODE;
        this.msg = "操作失败";
    }

    public void setError(String msg) {
        this.code = DEFAULT_ERROR_CODE;
        this.msg = msg;
    }

    public void setError(int code, String msg) {
        this.msg = msg;
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getDatas() {
        return data;
    }

    public void setDatas(T datas) {
        this.data = datas;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }
}
